package be.webchess.www.model;

public class ChessPiece {

	public enum PieceType {
		EPT_PAWN(1),
		EPT_KING(2),
		EPT_QUEEN(3),
		EPT_KNIGHT(4),
		EPT_BISHOP(5),
		EPT_ROOK(6);
		
		int		val;
		
		PieceType( int val ) {
			this.val = val;
		}
		
		public int		getValue ()
		{
			return val;
		}
		
		public void		setValue ( int value )
		{
			this.val = value;
		}
	}
	
	public static int	EPF_INITIAL_POSITION = 1;
	
	private long		id = -1;
	private ChessBoard	board;
	private String		location;
	private PieceType	type;
	private int		flags;
	private String		color;
	private String		movements;
	private String		init_movements;
	
	public String getImageFile ()
	{
		switch(type)
		{
			case EPT_BISHOP:
				return "piece_bishop_" + color + ".png";
			case EPT_PAWN:
				return "piece_pawn_" + color + ".png";
			case EPT_KING:
				return "piece_king_" + color + ".png";
			case EPT_QUEEN:
				return "piece_queen_" + color + ".png";
			case EPT_KNIGHT:
				return "piece_knight_" + color + ".png";
			case EPT_ROOK:
				return "piece_rook_" + color + ".png";
		}
		
		return "none.jpg";
	}

	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public String getLocation() {
		return location;
	}

	public void setLocation(String location) {
		this.location = location;
	}

	public PieceType getType() {
		return type;
	}

	public void setType(PieceType type) {
		this.type = type;
	}

	public int getFlags() {
		return flags;
	}

	public void setFlags(int flags) {
		this.flags = flags;
	}

	public void setBoard(ChessBoard board) {
		this.board = board;
	}

	public ChessBoard getBoard() {
		return board;
	}
	
	public String getColor() {
		return color;
	}

	public void setColor(String color) {
		this.color = color;
	}
	
	public String getMovements() {
		return movements;
	}

	public void setMovements(String movements) {
		this.movements = movements;
	}

	public String getInit_movements() {
		return init_movements;
	}

	public void setInit_movements(String init_movements) {
		this.init_movements = init_movements;
	}

	public static ChessPiece		createInitialPiece ( String location, PieceType type, ChessBoard board, String color )
	{
		ChessPiece			p = new ChessPiece();
		
		p.setLocation(location);
		p.setType(type);
		p.setBoard(board);
		p.setColor(color);
		p.setFlags(EPF_INITIAL_POSITION);
		
		switch(p.getType())
		{
			case EPT_BISHOP:
				p.setInit_movements("0,0,-1,-1:0,0,-1,-1");
				p.setMovements("0,0,-1,-1:0,0,-1,-1");
				break;
			case EPT_KING:
				p.setInit_movements("1,1,1,1:1,1,1,1");
				p.setMovements("1,1,1,1:1,1,1,1");				
				break;
			case EPT_KNIGHT:
				p.setInit_movements("0,2,0,0:0,2,0,0");
				p.setMovements("0,2,0,0:0,2,0,0");				
				break;
			case EPT_PAWN:
				p.setInit_movements("0,2,0,0:0,0,0,0");
				p.setMovements("0,1,0,0:0,0,0,0");				
				break;
			case EPT_QUEEN:
				p.setInit_movements("-1,-1,-1,-1:-1,-1,-1,-1");
				p.setMovements("-1,-1,-1,-1:-1,-1,-1,-1");				
				break;
			case EPT_ROOK:
				p.setInit_movements("-1,-1,0,0:-1,-1,0,0");
				p.setMovements("-1,-1,0,0:-1,-1,0,0");				
				break;
		}	
		
		return p;
	}
	
}
